package cn.vc.content.controller.video;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.content.service.video.VideoCoinsService;
import cn.vc.content.service.video.VideoService;
import cn.vc.content.util.SecurityUtil;
import cn.vc.wallet.feign.clients.WalletClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 投币接口
 */
@RestController
@RequestMapping("/videocoins")
//@PreAuthorize("hasAnyAuthority('ordinary')")
public class VideoCoinsController {
    @Autowired
    private  VideoCoinsService videoCoinsService;
    @Autowired
    private WalletClient walletClient;
    @Autowired
    private VideoService videoService;


    /**
     * 投币视频
     * @param id 视频ID
     */
    @PostMapping("/{id}/{coins}")
    public Result<?> like(@PathVariable("id") Long id, @PathVariable("coins") Long coins) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return new Result<>(0);
        boolean bo = videoCoinsService.coins(id, myUser.getId(), coins);
        if (bo) {
            walletClient.coinCasting(myUser.getId());
            videoService.coins(id, 1);
        }
        return new Result<>(bo);
    }
}
